package com.ruoyi.web.controller.wb;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.wb.domain.WbMaintainCompany;
import com.ruoyi.wb.dto.WbMaintainCompanyDto;
import com.ruoyi.wb.service.IWbMaintainCompanyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 维保公司Controller
 *
 * @author ruoyi
 * @date 2024-10-14
 */
@Api(tags="维保公司信息管理")
@RestController
@RequestMapping("/wb/wbMaintainCompany")
public class WbMaintainCompanyController extends BaseController {
    @Autowired
    private IWbMaintainCompanyService wbMaintainCompanyService;

    /**
     * 查询维保公司列表
     */
    @ApiOperation("查询维保公司列表")
    @GetMapping("/list")
    public TableDataInfo list(WbMaintainCompany wbMaintainCompany) {
        List<WbMaintainCompany> list = wbMaintainCompanyService.selectWbMaintainCompanyList(wbMaintainCompany);
        return getDataTable(list);
    }

    /**
     * 导出维保公司列表
     */
    @ApiOperation("导出维保公司列表")
    @Log(title = "维保公司", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WbMaintainCompany wbMaintainCompany) {
        List<WbMaintainCompany> list = wbMaintainCompanyService.selectWbMaintainCompanyList(wbMaintainCompany);
        ExcelUtil<WbMaintainCompany> util = new ExcelUtil<WbMaintainCompany>(WbMaintainCompany.class);
        util.exportExcel(response, list, "维保公司数据");
    }

    /**
     * 获取维保公司详细信息
     */
    @ApiOperation("获取维保公司详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(wbMaintainCompanyService.selectWbMaintainCompanyById(id));
    }

    /**
     * 新增维保公司
     */
    @ApiOperation("新增维保公司")
    @Log(title = "维保公司", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WbMaintainCompanyDto wbMaintainCompanyDto) {
        return toAjax(wbMaintainCompanyService.insertWbMaintainCompany(wbMaintainCompanyDto)>0?1:0);
    }

    /**
     * 修改维保公司
     */
    @ApiOperation("修改维保公司")
    @Log(title = "维保公司", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WbMaintainCompany wbMaintainCompany) {
        return toAjax(wbMaintainCompanyService.updateWbMaintainCompany(wbMaintainCompany));
    }

    /**
     * 删除维保公司
     */
    @ApiOperation("删除维保公司")
    @Log(title = "维保公司", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(wbMaintainCompanyService.deleteWbMaintainCompanyByIds(ids));
    }
}